ShieldJS.HtmlAction.addHTMLEleAction("dynamicConditionBtn_plugin", ".dynamicConditionBtn_plugin", function (contentE, menuli, menu, searchForm, shieldDialog) {

	let dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {

		// 提交的表单
		let $form = contentE.find("form");

		// 动态条件配置项
		let dynamicConditionalConfigurationItem = [];
		contentE.find("#dynamicConditionalConfigurationItem").find("tr").each(function (index) {
			let tr = [];
			let $tr = $(this);
			$tr.find("td").each(function (index) {
				let $td = $(this);
				tr.push($td.html().replaceAll("noshield", "required"));
			});
			dynamicConditionalConfigurationItem.push(tr);
		});

		// 符号键值对
		let markMap = new Map();
		markMap.put('equal_', '等于');
		markMap.put('notEqual_', '不等于');
		markMap.put('like_', '包含');
		markMap.put('like1_', '开头字符');
		markMap.put('like2_', '结尾字符');
		markMap.put('date_s', '日期大于等于');
		markMap.put('date_e', '日期小于等于');

		// 缓存条件的值
		let cacheCondition = [];

		// 普通查询
		let legacyCondition;

		// 是否使用分组
		let whetherToUseGrouping = false;

		// form 中动态条件查询表格
		let dynamicConditionTable =
			'<table id="dynamicCondition" style="display: none">\n' +
			'    <tr>\n' +
			'        <th class="taCenter grouping">左括号(用于分组)</th>\n' +
			'        <th class="taCenter">条件项</th>\n' +
			'        <th class="taCenter">符号</th>\n' +
			'        <th class="taCenter">值</th>\n' +
			'        <th class="taCenter grouping">右括号(用于分组)</th>\n' +
			'        <th class="taCenter">关系</th>\n' +
			'        <th class="taCenter">操作</th>\n' +
			'    </tr>\n' +
			'</table>';

		// 动态条件按钮点击事件
		$form.on("click", this.expression, function () {

			// form 中避免重复插入动态条件查询表格
			let existDynamicConditionTable = $form.find("#dynamicCondition");
			if (existDynamicConditionTable.length === 0) {
				//#searchResult 是接受内容的一个id，经常任意定义，不能用固定的id接受
				//$form.find("#searchResult").before(dynamicConditionTable);
				$form.append(dynamicConditionTable);
			}

			ShieldJS.openDialog("dynamicCondition/toDynamicCondition", {}, function (ele, dialog, index) {

				// 拷贝dom并赋值
				let copyAndAssignment = function (source, target) {
					target.html(source.html());
					target.find("tr").not("tr:first").each(function (index) {
						$(this).find(".leftParenthesis").val(cacheCondition[index][0]);
						$(this).find(".conditionItem").val(cacheCondition[index][1]);
						$(this).find(".mark").val(cacheCondition[index][2]);
						$(this).find(".markConditionItem").val(cacheCondition[index][3]);
						$(this).find(".conditionValue").val(cacheCondition[index][4]);
						$(this).find(".rightParenthesis").val(cacheCondition[index][5]);
						$(this).find(".relationship").val(cacheCondition[index][6]);
					});
				};

				// 把 searchForm 的条件拷贝到弹框中并赋值
				copyAndAssignment($form.find("#dynamicCondition"), ele.find("#condition"));

				// 为条件项赋值
				let conditionItemOptions = '';
				for (let conditionItemElement of dynamicConditionalConfigurationItem) {
					conditionItemOptions += '<option value=' + conditionItemElement[0] + '>' + conditionItemElement[1] + '</option>';
				}
				ele.find("#conditionTemplate tbody").find(".conditionItem").find("option:first").after(conditionItemOptions);
				// 默认不使用分组
				let clickNum = 0;
				if (!whetherToUseGrouping) {
					ele.find(".grouping").hide();
					ele.find("#useGrouping").val("使用分组");
				} else {
					ele.find("#useGrouping").val("不使用分组");
					clickNum = 1;
				}
				// 是否使用分组
				ele.find("#useGrouping").click(function () {
					if (clickNum === 0) {
						whetherToUseGrouping = true;
						ele.find(".grouping").show();
						ele.find("#useGrouping").val("不使用分组");
						clickNum = 1;
					} else {
						whetherToUseGrouping = false;
						ele.find(".grouping").hide();
						ele.find(".grouping").find('.leftParenthesis,.rightParenthesis').each(function () {
							$(this).val(0);
						});
						ele.find("#useGrouping").val("使用分组");
						clickNum = 0;
					}
				});

				// 添加一行新条件
				ele.find("#addCondition").click(function () {
					let conditionTemplate = ele.find("#conditionTemplate tbody");
					if (!whetherToUseGrouping) {
						conditionTemplate.find(".grouping").hide();
					}
					ele.find("#condition tbody").append(conditionTemplate.html().replaceAll("noshield", "required"));
					var dialogContentE = ele.find("#condition");
		    		var titleHeight = ele.find(".layui-layer-title").height();
		    		/*自身内容发生变化时，layui-layer-content为dialog的内容区*/
		    		dialogContentE.resize(function() {
		    				dialog.resize(); //调用resize方法
		            });
				});

				// 默认添加展示一行搜索
				if(ele.find("#condition tbody").find("tr").length==1)
				{
					ele.find("#addCondition").click();
				}
				// 条件项切换
				ele.find("#condition").on('change', '.conditionItem', function () {
					$(this).closest("tr").find(".mark option").not("option:first").remove();
					let conditionItemValue = $(this).val();

					// 找当前条件项对应的值选项
					let conditionLength = dynamicConditionalConfigurationItem.length;
					for (let i = 0; i < conditionLength; i++) {
						if (dynamicConditionalConfigurationItem[i][0] === conditionItemValue) {
							let markElement = dynamicConditionalConfigurationItem[i][2];
							let markElementSplit = markElement.split(',');
							let markOptions = '';
							for (let mark of markElementSplit) {
								markOptions += '<option value=' + mark + '>' + markMap.get(mark) + '</option>';
							}
							$(this).closest("tr").find(".mark").append(markOptions);
							break;
						}
					}
				});

				// 符号切换
				ele.find("#condition").on('change', '.mark', function () {
					$(this).closest("tr").find(".conditionValues").empty();
					let conditionItemValue = $(this).closest("tr").find('.conditionItem').val();
					// 找当前条件项对应的值选项
					let conditionLength = dynamicConditionalConfigurationItem.length;
					for (let i = 0; i < conditionLength; i++) {
						if (dynamicConditionalConfigurationItem[i][0] === conditionItemValue) {
							$(this).closest("tr").find(".conditionValues").append(dynamicConditionalConfigurationItem[i][3]);
							break;
						}
					}
				});

				// 删除一行条件
				ele.find("#condition").on('click', '#delCondition', function () {
					$(this).closest("tr").remove();
					// 调整弹出框宽高度
					let height = ele.find(".contentBody").height();
					let width = ele.find(".contentBody").width();
					dialog.resize(index, width, height);
				});

				// 弹框查询
				ele.find("#determineConditions").click(function () {
					let keepGoing = ele.kvvalid();
					if (keepGoing) {
						cacheCondition = [];
						// 弹框的值放到数组中
						ele.find("#condition").find("tr").not("tr:first").each(function (index) {
							let oneConditionValues = [];
							let leftParenthesis = $(this).find(".leftParenthesis").val();
							let conditionItem = $(this).find(".conditionItem").val();
							let mark = $(this).find(".mark").val();
							let conditionValue = $(this).find(".conditionValue").val();
							let rightParenthesis = $(this).find(".rightParenthesis").val();
							let relationship = $(this).find(".relationship").val();
							oneConditionValues.push(leftParenthesis);
							oneConditionValues.push(conditionItem);
							oneConditionValues.push(mark);
							oneConditionValues.push(mark + conditionItem);
							oneConditionValues.push(conditionValue);
							oneConditionValues.push(rightParenthesis);
							oneConditionValues.push(relationship);
							cacheCondition.push(oneConditionValues);
						});

						// 把弹框中的条件拷贝到 searchForm 并赋值
						copyAndAssignment(ele.find("#condition"), $form.find("#dynamicCondition"));

						dialog.remove();
						legacyCondition = $form.find(".search-box").html();
						$form.find(".search-box").empty();
						$form.submit();
						$form.find(".search-box").html(legacyCondition);
					}
				});
			}, "高级查询选择", 1050);
		});

		// 去除动态条件，使用普通查询
		$form.on("click", "input[type='submit']", function () {
			$form.find("#dynamicCondition tbody").find("tr").not("tr:first").remove();
			$form.submit();
		});
	}
}, "动态条件选择器插件");